import { log } from "console";

namespace MyNamespace {
  // 可选属性接口
  interface Product {
    name: string;
    price: number;
    description?: string;
  }
  const product: Product = {
    name: '香蕉',
    price: 10,
  }
  console.log(product.name);

  // 1.用户信息接口
  interface User {
    id: number;
    username: string;
    email: string;
    isActive: boolean;
  }
  const user: User = {
    id: 1,
    username: 'xiaowei',
    email: '3233465356@qq.com',
    isActive: true,
  }
  console.log(user.username);

  // 2.函数类型接口
  interface MathOperation {
    (a: number, b: number): number;
  }
  const add: MathOperation = (a, b) => a + b;
  console.log(add(3, 6));
  // 3.数组类型接口
  interface StringArray {
    [index: number]: string;
  }
  const names: StringArray[] = ['Alice', 'BOb', 'Charlie'];
  names.forEach(name => console.log(name));
  console.log('----------------');

  // 5.只读属性接口
  interface Coordinates {
    readonly x: number;
    readonly y: number;
  }
  const point: Coordinates = {
    x: 20,
    y: 27
  };
  console.log(point.x);
  console.log(point.y);
  console.log('----------------');


  // 6.混合类型接口
  interface Counter{
    value: number;
    (): number;
  }
  const counter: Counter = (() => {
    let count = 0;
    const c = () => ++count;
    c.value = 0;
    return c;
  })();
  console.log(counter());
  console.log(counter.value);
  console.log('----------------');
  

  // 7.索引签名接口
  interface StringDictionary{
    [key: string]: string;
  }
  const dictionary: StringDictionary = {
    hello: '你好',
    world: '世界',
  };
  console.log(dictionary.hello);
  console.log(dictionary.world);
  console.log('--------------------');

  // 8.接口继承
  interface Animal{
    name: string;
    age: number;
  }
  interface Dog extends Animal{
    breed: string;
  }
  const myDog: Dog = {
    name: '小伟',
    age: 2,
    breed:'金毛'
  }
  console.log(myDog.name);
  console.log(myDog.age); 
  console.log(myDog.breed);
  console.log('--------------------');
  //9.接口合并
  interface Person{
    name: string;
    age: number;
  }
  interface Employee{
    employeeId: number;
  }
  interface Worker extends Person, Employee{ }
  const worker: Worker = {
    name: '老戴',
    age: 30,
    employeeId: 368296739
  };
  console.log(worker.name);
  console.log(worker.age);
  console.log(worker.employeeId); 
  console.log('--------------------');

  // 10.索引类型查询操作符
  interface Person{
    name: string;
    age: number;
  }
  interface KeyValuePair<K extends keyof Person, V extends Person[K]>{
    key: K;
    value: V;
  }
  const namePair: KeyValuePair<'name', string> = {
    key: 'name',
    value: 'Commy'
  };
  console.log(namePair.key);
  console.log(namePair.value);
  console.log('---------------------');
  

  
  
  
  
  

  
  



  
  
  
  
  
  






}






